package tv.youxing.android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import tv.youxing.android.R;

/**
 * Created by apple on 17/3/21.
 */

/**
 * 项目名：   Dbs
 * 包名：     com.lizi.dbs.adapter
 * 文件名：   HotWordAdapter
 * 创建者：   叶克武
 * 创建时间： 17/3/21 上午11:19
 * 描述：    TODO
 */
public class HotWordAdapter extends BaseAdapter {

    private Context context;
    private List<String> list = new ArrayList<>();
    private LayoutInflater layoutInflater;

    public HotWordAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
        layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (viewHolder==null) {
            viewHolder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.layout_item_hotword,null);
            viewHolder.tvHotWord = (TextView) convertView.findViewById(R.id.tvHotWord);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        String obj = list.get(position);
        viewHolder.tvHotWord.setText(obj);

        return convertView;
    }

    class ViewHolder{
        private TextView tvHotWord;
    }

}
